<template>
  <div class="intentionAdds addButton">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>教务管理</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/education/season/list' }">考季管理</el-breadcrumb-item>
      <el-breadcrumb-item>添加考季</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="form">
      <el-form ref="form" :model="form" label-width="100px" size="small" :rules="rules">
        <el-form-item label="考季名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入考季名称" size="small" style="width:230px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="background:#ff8b00;color:#fff" @click="onSubmit" :disabled="isDisabled">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>

</template>
<script>
export default {
  data() {
    return {
      form: {
        name: "",
      },
      rules: {
        name: [
          { required: true, message: "请填写考季名称", trigger: "blur" },
          { min: 3, max: 50, message: "长度在 3 到 50 个字符", trigger: "blur" }
        ],
      },
      isDisabled: false,
    };
  },
  methods: {
    //添加部门
    onSubmit() {
      if (this.form.name.replace(/(^\s*)|(\s*$)/g, "") == "") {
        this.$message.error("请输入正确的考季名称！");
        return;
      }
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.isDisabled = true;
          this.$api.education.seasonAdd({ name: this.form.name })
            .then(res => {
              if (res.code === 200) {
                this.$message.success("添加成功！");
                this.form.name="";
              }
              this.isDisabled = false;
            }).catch(() => {
            this.isDisabled = false;
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  },
};
</script>
<style scoped>
.intentionAdds {
  padding: 30px;
}

.intentionAdds .form {
  max-width: 700px;
  margin: 30px 0px;
}
</style>
